<?php
sleep(1);
error_reporting(0);

$email = preg_replace( "/\n/", " ", $_GET['email'] ); 
$fromemail = preg_replace( "/\n/", " ", $_GET['fromemail'] ); 
$title = preg_replace( "/\n/", " ", $_GET['title'] ); 
$url   = preg_replace( "/\n/", " ", $_GET['url'] ); 
$email = preg_replace( "/\r/", " ", $email ); 
$fromemail = preg_replace( "/\r/", " ", $fromemail ); 
$title = preg_replace( "/\r/", " ", $title ); 
$url   = preg_replace( "/\r/", " ", $url ); 

$senderemail = $fromemail; 

//check that valid email was entered
function check_email_address($verify) {
  // First, we check that there's one @ symbol, 
  // and that the lengths are right.
  if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $verify)) {
    // Email invalid because wrong number of characters 
    // in one section or wrong number of @ symbols.
    return false;
  }
  // Split it into sections to make life easier
  $verify_array = explode("@", $verify);
  $local_array = explode(".", $verify_array[0]);
  for ($i = 0; $i < sizeof($local_array); $i++) {
    if
(!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&
?'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
$local_array[$i])) {
      return false;
    }
  }
  // Check if domain is IP. If not, 
  // it should be valid domain name
  if (!ereg("^\[?[0-9\.]+\]?$", $verify_array[1])) {
    $domain_array = explode(".", $verify_array[1]);
    if (sizeof($domain_array) < 2) {
        return false; // Not enough parts to domain
    }
    for ($i = 0; $i < sizeof($domain_array); $i++) {
      if
(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|
?([A-Za-z0-9]+))$",
$domain_array[$i])) {
        return false;
      }
    }
  }
  return true;
}

//if email is valid send message
if(check_email_address($email) && check_email_address($senderemail)){
$extra 		= "From: <$senderemail>\n";
$extra 		.= "Content-Type: text/html; charset=utf-8;\n Content-Transfer-Encoding: 8bit\n";
$messaging 	= "This email is sent to you in part by:  $senderemail<br/><br/><p>Hello,<br/><br/>Your friend has been to our site TotalMusicSource.com, and wants you to know about this page: <a href=\"$url\" title=\"$title\">$url</a>.</p><p>If the product in question doesn't interest you, then why not shop around our store for something else.</p>Thank you,<br/>TotalMusicSource.com";
	if(mail($email,"$title",$messaging,$extra)){
		echo "<div align='center'><span style=\"color:#000\">Your mail has been sent!</span></div>";
	}
}else{
echo "<div align='center'><span style=\"color:#000\">Sorry, error sending email!</span></div>";
}
?>